/*接口地址*/
// var oldApiUrl = 'http://192.168.1.11:7888/';
// var apiUrl = 'http://192.168.1.11:7888/api/v1/';

var oldApiUrl = 'http://bowen.sports-qg.com/';
var apiUrl = 'http://dev.dxnet2.com';
var apiHeader = {
    "X-Token": $api.getStorage('token')
};
var apiImageUrl = 'http://image.sports-qg.com/';
// var apiImageUrl = 'http://boox.77taoletao.com/';

/*rem转换*/
(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 100 * (clientWidth / 375) + 'px';
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

/*引入模块*/
var fs;
function moduleInit() {
    // 文件模块
    fs = api.require("fs");
}

//关闭app
function exitApp() {
    api.addEventListener({
        name: "keyback"
    }, function (ret, err) {
        api.toast({
            msg: "再按一次退出程序",
            duration: 2000,
            location: "bottom"
        });
        api.addEventListener({
            name: "keyback"
        }, function (ret, err) {
            api.closeWidget({
                id: "A6090250374516", //这里改成自己的应用ID
                retData: {
                    name: "closeWidget"
                },
                silent: true
            });
        });
        setTimeout(function () {
            exitApp();
        }, 2000);
    });
}

function fun_date(num){
    var date0 = [];
    var date1 = new Date();
    var date2 = new Date(date1);
    date2.setDate(date1.getDate()+num);

    var week = date2.getDay();
    if (week == 0){
        week = 6;
    } else {
        week -= 1;
    }
    date0["week"] = week;
    var month = date2.getMonth("mm")+1;
    date0["month"] = month;
    if (month<10) {
        month = "0" + month;
    }
    var day = date2.getDate();
    date0["day"] = day;
    if (day<10) {
        day = "0" + day;
    }
    var year = date2.getFullYear();
    date0["year"] = year;
    date0["date"] = year+"-"+month+"-"+day;

    return date0;
}


function formatNumberRgx(num) {
    var parts = num.toString().split(",");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(",");
}

function formatTime (time) {
    let unixtime = time;
    let unixTimestamp = new Date(unixtime * 1000);
    let Y = unixTimestamp.getFullYear();
    let M = ((unixTimestamp.getMonth() + 1) > 10 ? (unixTimestamp.getMonth() + 1) : '0' + (unixTimestamp.getMonth() + 1));
    let D = (unixTimestamp.getDate() > 10 ? unixTimestamp.getDate() : '0' + unixTimestamp.getDate());
    let toDay = Y + '-' + M + '-' + D;
    return toDay
}

function formatTimeSecond (time) {
    let unixtime = time;
    let unixTimestamp = new Date(unixtime * 1000);
    let H = ((unixTimestamp.getHours() + 1) > 10 ? (unixTimestamp.getHours() + 1) : '0' + (unixTimestamp.getHours() + 1));
    let M = (unixTimestamp.getMinutes() > 10 ? unixTimestamp.getMinutes() : '0' + unixTimestamp.getMinutes());
    let secomd = H + ':' + M;
    return secomd
}

function remainTime (time) {
    var remainTimeText;
    let timeSecond = time - parseInt(new Date().getTime() / 1000);
    if (timeSecond <= 0) {
        remainTimeText = '0天' + '0小时' + '0分';
    } else {
        let d = parseInt(timeSecond / 86400);
        let h = parseInt((timeSecond - (d * 86400)) / 3600);
        let m = parseInt((timeSecond - (d * 86400) - (h * 3600)) / 60);

        remainTimeText = d + '天' + h + '小时' + m + '分';
    }

    return remainTimeText
}
